package com.businessportal.web.dataaccess.services;

import com.businessportal.web.dataaccess.dao.IUploadsDao;
import com.businessportal.web.dataaccess.dao.UploadsDao;
import com.businessportal.web.dataaccess.entities.Login;
import com.businessportal.web.dataaccess.entities.Uploads;

import java.util.List;
import java.util.Set;

/**
 * Created by Vadim on 7/20/14.
 */
public enum UploadsService {
    INSTANCE;

    private IUploadsDao dao = new UploadsDao();

    private UploadsService(){

    }

    public Uploads AddNewUpload(String link, String localFilePath, Login owner, long size){
        Uploads newUpload = new Uploads(link, localFilePath);
        newUpload.setLogin_id(owner.getId());
        newUpload.setSize(size);
        dao.save(newUpload);
        return newUpload.getId() != null && newUpload.getId() > 0 ? newUpload : null;
    }

    public Set<Uploads> getAllUploadsForUser(Login user){
        return dao.getUploadsForUser(user);
    }

    public void deleteById(Long id){
        dao.deleteById(id);
    }

    public Uploads getBiId(Long id){
        return dao.getById(id);
    }

    public void delete(Uploads entity){
        dao.delete(entity);
    }
}
